VBScript → Lua
This function calls (launches) a given URL (http request) and returns True if the request returns without error.
Please see the Introduction chapter for some usage instructions.
'-------------------------------------------------------------------
' LaunchHTTPRequest
'
' Launches given URL.
'
' Parameter:
' sURL complete url
'
' return value:
' boolean True - request file processed
' False - request file *not* processed
'--------------------------------------------------------------------
Function LaunchHTTPRequest(ByVal sURL)
PBXScript.OutputTrace "------> LaunchHTTPRequest ( sURL = '" & sURL & "' )"
On Error Resume Next
Dim bReturn
bReturn = True
Dim HTTP_REQ
Set HTTP_REQ = CreateObject("Msxml2.ServerXMLHTTP.3.0")
Dim lResolve, lConnect, lSend, lReceive
lResolve = 1 * 60 * 1000 ' 1 minute (default: infinte)
lConnect = 1 * 60 * 1000 ' 1 minute (default)
lSend = 60 * 60 * 1000 ' 1 hour (default: 30 seconds)
lReceive = 60 * 60 * 1000 ' 1 hour (default: 30 seconds)
HTTP_REQ.setTimeouts lResolve, lConnect, lSend, lReceive
Dim vBefore, vAfter, nDuration
vBefore = Now
HTTP_REQ.open "GET", sURL, False
HTTP_REQ.send
If Err <> 0 Then
PBXScript.OutputTrace "Error sending http request (" & Hex(Err) & ")"
PBXScript.OutputTrace Err.Description
Err.Clear
Else
vAfter = Now
nDuration = DateDiff("s", vBefore, vAfter)
PBXScript.OutputTrace "HTTP Request returned after " & nDuration & " seconds"
bReturn = True
End If
Set HTTP_REQ = Nothing
LaunchHTTPRequest = bReturn
PBXScript.OutputTrace "bReturn = " & bReturn
PBXScript.OutputTrace "<------ LaunchHTTPRequest"
End Function
This function makes use of the Server Script API function PBXScript.OutputTrace to write trace information into the SwyxServer trace file.
Another version of this function which makes use of the PBXScript.WebRequest object (which was introduced with SwyxWare 12.40) to perform the web request can be found in the LaunchHTTPRequestEx function.
This function was initially posted into this forum topic.
By Tom Wellige
